package com.huishi.ui;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 功能选择：文件落盘、数据迁移
 */
//@Component
public class FunctionSelectionUI extends JFrame {

    @Autowired
    private FileChooserUI fileChooserUI;

    @Autowired
    private DataMigrationUI dataMigrationUI;

    @Autowired
    private DataSyncUI dataSyncUI;

    private JButton fileUploadButton;
    private JButton dataMigrationButton;

    public FunctionSelectionUI() {
        setTitle("功能选择");
        setSize(400, 200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        // 初始化按钮
        fileUploadButton = new JButton("文件落盘");
        dataMigrationButton = new JButton("数据同步");

        // 添加按钮点击事件监听器
        fileUploadButton.addActionListener(e -> {
            setVisible(false);// 隐藏功能选择界面
            fileChooserUI.setVisible(true);// 显示文件落盘界面
        });

        dataMigrationButton.addActionListener(e -> {
            // 显示数据迁移界面
            setVisible(false);
            dataSyncUI.setVisible(true);
        });

        // 设置布局为网格布局
        setLayout(new GridLayout(2, 1));

        // 将按钮添加到界面中
        add(fileUploadButton);
        add(dataMigrationButton);

        setVisible(true);
    }

//    public static void main(String[] args) {
//        // 创建并显示功能选择界面
//        SwingUtilities.invokeLater(new Runnable() {
//            @Override
//            public void run() {
//                new FunctionSelectionUI().setVisible(true);
//            }
//        });
//    }
}

